from calm.sensor import Sensor
from ai.bin import decode
from system.vec2 import Vec2

class DistSensor(Sensor):
    def __init__(self, controller, vars):
        if vars.has_key("numSlices"):
            self.numSlices = vars['numSlices']
        else:
            self.numSlices = 2
        self.minDist = 0
        self.maxDist = 1000
        self.point = (0,0)
        
        Sensor.__init__(self, controller, vars, self.numSlices)
        
    def acceptBits(self, bits):
        dist = (Vec2(self.point) - Vec2(self.agent.getVar("pos"))).length()
        if dist < self.minDist or dist >= self.maxDist:
            return False
        distStep = (self.maxDist - self.minDist) / float(self.numSlices)
        distPos = int((dist - self.minDist) / distStep)
        #print dist, distStep, distPos
        return bits[distPos]
